import {
	api,
	BASE_URL
} from '../js/api.js';
import {
	defineStore
} from 'pinia';

const EMPTY = {
	user: {},
	info: {},
	logo: ''
}

const store = defineStore('user', {
	state() {
		return {
			islogin: false,
			userinfo: EMPTY
		};
	},
	actions: {
		queryUser(cb) {
			let instance = this;
			api.get('/auth/info', {}, (data) => {
				if (data.success) {
					instance.islogin = true;
					instance.userinfo = data.data;
					instance.userinfo.logo =
						BASE_URL + '/user/info/logo/' + instance.userinfo.user.id
				} else {
					instance.islogin = false;
					instance.userinfo = EMPTY;
				}
				cb?.(data.success);
			});
		},
	},
});

export default store;